package com.qdsg.ysg.doctor.ui.fragment;//package com.qdsg.ysg.doctor.ui.fragment;
//
//import android.graphics.Canvas;
//import android.graphics.Color;
//import android.graphics.Rect;
//import android.os.Bundle;
//import android.support.v7.widget.LinearLayoutManager;
//import android.support.v7.widget.RecyclerView;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.ViewGroup;
//import android.widget.RelativeLayout;
//import android.widget.TextView;
//import android.widget.Toast;
//
//import com.rest.business.RestProxy;
//import com.rest.exception.BusinessException;
//import com.rest.response.BaseResponse;
//import com.rest.response.ImageConsultationListResponse;
//import com.rest.response.KaYiUrlResponse;
//import com.scwang.smartrefresh.layout.api.RefreshLayout;
//import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
//import com.scwang.smartrefresh.layout.footer.BallPulseFooter;
//import com.scwang.smartrefresh.layout.header.ClassicsHeader;
//import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
//import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
//
//import java.util.ArrayList;
//import java.util.List;
//
//import butterknife.BindView;
//import butterknife.OnClick;
//import io.reactivex.Observer;
//import io.reactivex.disposables.Disposable;
//import com.qdsg.ysg.doctor.R;
//import com.qdsg.ysg.doctor.base.BaseApplication;
//import com.qdsg.ysg.doctor.base.BaseFragment;
//import com.qdsg.ysg.doctor.ui.AddReferralActivity;
//import com.qdsg.ysg.doctor.ui.WebViewActivity;
//import com.qdsg.ysg.doctor.ui.widget.CustomPopWindow;
//
///**
// * Created by Administrator on 2018/5/25.
// */
//
//public class ImageConsultationYJChildFragment extends BaseFragment {
//    private static ImageConsultationYJChildFragment imageConsultationFragment;
//
//    @BindView(R.id.refreshLayout)
//    RefreshLayout refreshLayout;
//    @BindView(R.id.recyclerView)
//    RecyclerView recyclerView;
//    @BindView(R.id.btn_consultation)
//    TextView btn_consultation;
//    @BindView(R.id.tv_title)
//    TextView tv_title;
//    @BindView(R.id.title)
//    RelativeLayout title;
//    int type;
//
//    MyAdapter adapter;
//    private CustomPopWindow mListPopWindow;
//
//    List<ImageConsultationListResponse.ImageConsultation> list = new ArrayList<>();
//
//    public static ImageConsultationYJChildFragment newInstance(int type) {
//        Bundle args = new Bundle();
//        args.putInt("type", type);
//        ImageConsultationYJChildFragment fragment = new ImageConsultationYJChildFragment();
//        fragment.setArguments(args);
//        return fragment;
//    }
//
//    @Override
//    protected int getLayoutResource() {
//        return R.layout.fragment_consultation;
//    }
//
//    @Override
//    protected void initView() {
//        LinearLayoutManager manager = new LinearLayoutManager(getActivity());
//        manager.setOrientation(LinearLayoutManager.VERTICAL);
//        recyclerView.setLayoutManager(manager);
//        adapter = new MyAdapter();
//        recyclerView.setAdapter(adapter);
//        recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
//            @Override
//            public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
//                super.onDraw(c, parent, state);
//            }
//
//            @Override
//            public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
//                super.getItemOffsets(outRect, view, parent, state);
//                outRect.bottom = 1;
//            }
//        });
//        refreshLayout.setRefreshFooter(new BallPulseFooter(getActivity()).setSpinnerStyle(SpinnerStyle.Scale));
//        refreshLayout.setRefreshHeader(new ClassicsHeader(getActivity()));
//        refreshLayout.setEnableLoadMore(false);
//        refreshLayout.setOnRefreshListener(new OnRefreshListener() {
//            @Override
//            public void onRefresh(RefreshLayout refreshlayout) {
//                switch (type) {
//                    case 1:
//                        getYJConsultationList("0", "0");
//                        break;
//                    case 2:
//                        getYJConsultationList("0", "2");
//                        break;
//                    case 3:
//                        getYJConsultationList("1", "1");
//                        break;
//                    case 4:
//                        getYJConsultationList("1", "3");
//                        break;
//                }
//            }
//        });
//        refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
//            @Override
//            public void onLoadMore(RefreshLayout refreshlayout) {
//
//            }
//        });
//        if (BaseApplication.userType == 1) {
//            btn_consultation.setVisibility(View.VISIBLE);
//        } else if (BaseApplication.userType == 2) {
//            btn_consultation.setVisibility(View.GONE);
//        }
//        tv_title.setText("影像诊断");
//        title.setVisibility(View.GONE);
//    }
//
//    @Override
//    protected void initData() {
//        type = getArguments().getInt("type");
////        if (BaseApplication.userType == 1) {
////            getConsultationBaseList();
////        } else if (BaseApplication.userType == 2) {
////            getConsultationProList();
////        }
//    }
//
//    class MyAdapter extends RecyclerView.Adapter<MyAdapter.Holder> {
//
//        @Override
//        public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
//            MyAdapter.Holder myHolder = new MyAdapter.Holder(LayoutInflater.from(getActivity()).inflate(R.layout.item_consultation, parent, false));
//            return myHolder;
//        }
//
//        @Override
//        public void onBindViewHolder(Holder holder, final int position) {
//            holder.itemView.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    getKaYiUrl(list.get(position).kaYiPascId);
//                }
//            });
//            holder.tv_zs_name.setText("影像类型");
//            holder.tv_reason.setText(list.get(position).pacsTypeStr);
//            holder.tv_time.setText(list.get(position).creatDate);
//            holder.tv_patient_name.setText(list.get(position).patientName);
//            holder.tv_hint.setText(list.get(position).statusDesc);
//            holder.tv_hospita_name.setText("接受医院：");
//            holder.tv_hospital.setText(list.get(position).hosName);
//            holder.tv_patient_age.setText(list.get(position).patientAge);
//            holder.tv_patient_gender.setText(list.get(position).sex);
//            if (list.get(position).flag == 0) {
//                holder.button1.setText("拒绝");
//                holder.button2.setText("接受");
//                holder.button2.setTextColor(Color.parseColor("#27a29d"));
//                holder.button2.setBackgroundResource(R.drawable.item_bg_green_circle);
//                holder.button1.setVisibility(View.VISIBLE);
//                holder.button2.setVisibility(View.VISIBLE);
//            } else {
//                if (type == 3) {
//                    holder.button1.setText("查看详情");
//                    holder.button1.setVisibility(View.VISIBLE);
//                    holder.button2.setVisibility(View.GONE);
//                } else {
//                    if (list.get(position).docflag == 0) {
//                        holder.button1.setText("开始诊断");
//                        holder.button1.setVisibility(View.VISIBLE);
//                        holder.button2.setVisibility(View.GONE);
//                    } else if (list.get(position).docflag == 2) {
//                        holder.button1.setText("开始审核");
//                        holder.button1.setVisibility(View.VISIBLE);
//                        holder.button2.setVisibility(View.GONE);
//                    } else if (list.get(position).docflag == 1) {
//                        holder.button1.setText("查看详情");
//                        holder.button1.setVisibility(View.VISIBLE);
//                        holder.button2.setVisibility(View.GONE);
//                    } else if (list.get(position).docflag == 3) {
//                        holder.button1.setText("查看详情");
//                        holder.button1.setVisibility(View.VISIBLE);
//                        holder.button2.setVisibility(View.GONE);
//                    }
//                }
//            }
//
//            holder.button1.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    if (list.get(position).flag == 0) {
//                        agreeConsultation(list.get(position).dispatchDiagId, list.get(position).diagPascId, list.get(position).dispatchType, "1");
//                    } else {
//                        if (type == 3) {
//                            getKaYiUrl(list.get(position).kaYiPascId);
//                        } else {
//                            if (list.get(position).docflag == 0) {
//                                getKaYiYJUrl(list.get(position).dispatchType, list.get(position).kaYiPascId, list.get(position).pascType, list.get(position).kayiCheckPart, list.get(position).recDocId, list.get(position).recDocName);
//                            } else if (list.get(position).docflag == 2) {
//                                getKaYiYJUrl(list.get(position).dispatchType, list.get(position).kaYiPascId, list.get(position).pascType, list.get(position).kayiCheckPart, list.get(position).recDocId, list.get(position).recDocName);
//                            } else if (list.get(position).docflag == 1) {
//                                getKaYiUrl(list.get(position).kaYiPascId);
//                            } else if (list.get(position).docflag == 3) {
//                                getKaYiUrl(list.get(position).kaYiPascId);
//                            }
//                        }
//                    }
//                }
//            });
//            holder.button2.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    if (list.get(position).flag == 0) {
//                        agreeConsultation(list.get(position).dispatchDiagId, list.get(position).diagPascId, list.get(position).dispatchType, "0");
//                    }
//                }
//            });
//        }
//
//        @Override
//        public int getItemCount() {
//            return list.size();
//        }
//
//        class Holder extends RecyclerView.ViewHolder {
//
//            TextView tv_reason, tv_time, tv_id_card, tv_patient_name, tv_hint, tv_patient_gender, tv_patient_age, button1, button2, tv_hospital, tv_hospita_name, tv_zs_name;
//
//            public Holder(View itemView) {
//                super(itemView);
//                tv_zs_name = itemView.findViewById(R.id.tv_zs_name);
//                tv_reason = itemView.findViewById(R.id.tv_reason);
//                tv_time = itemView.findViewById(R.id.tv_time);
//                tv_id_card = itemView.findViewById(R.id.tv_id_card);
//                tv_patient_name = itemView.findViewById(R.id.tv_patient_name);
//                tv_hint = itemView.findViewById(R.id.tv_hint);
//                tv_patient_gender = itemView.findViewById(R.id.tv_patient_gender);
//                tv_patient_age = itemView.findViewById(R.id.tv_patient_age);
//                tv_hospital = itemView.findViewById(R.id.tv_hospital);
//                tv_hospita_name = itemView.findViewById(R.id.tv_hospita_name);
//                button1 = itemView.findViewById(R.id.button1);
//                button2 = itemView.findViewById(R.id.button2);
//            }
//        }
//
//    }
//
//    @Override
//    public void onResume() {
//        switch (type) {
//            case 1:
//                getYJConsultationList("0", "0");
//                break;
//            case 2:
//                getYJConsultationList("0", "2");
//                break;
//            case 3:
//                getYJConsultationList("1", "1");
//                break;
//            case 4:
//                getYJConsultationList("1", "3");
//                break;
//        }
//        super.onResume();
//    }
//
//    @OnClick(R.id.btn_consultation)
//    void btn_consultation() {
//        Bundle bundle = new Bundle();
//        bundle.putInt("type", 2);
//        startActivity(AddReferralActivity.class, bundle);
//    }
//
//
////    private void getConsultationBaseList() {
////        RestProxy.getInstance().getConsultationList(1 + "", 50 + "", 2 + "", "102", new Observer<ConsulationResponse>() {
////            @Override
////            public void onSubscribe(Disposable d) {
////
////            }
////
////            @Override
////            public void onNext(ConsulationResponse consulationResponse) {
////                list.clear();
////                list.addAll(consulationResponse.data.records);
////                adapter.notifyDataSetChanged();
////            }
////
////            @Override
////            public void onError(Throwable e) {
////                refreshLayout.finishLoadMore(true/*,false*/);//传入false表示加载失败
////                refreshLayout.finishRefresh(true/*,false*/);//传入false表示加载失败
////                if(e instanceof BusinessException){
////                    if(((BusinessException)e).errorCode == 700){
////                        Toast.makeText(getActivity(),"登录失败，请重新登录",Toast.LENGTH_SHORT).show();
////                    }
////                }
////            }
////
////            @Override
////            public void onComplete() {
////                refreshLayout.finishLoadMore(true/*,false*/);//传入false表示加载失败
////                refreshLayout.finishRefresh(true/*,false*/);//传入false表示加载失败
////            }
////        });
////    }
//
//
//    private void getYJConsultationList(String flag, String docFlag) {
//        RestProxy.getInstance().getYJConsultationList(flag, docFlag, "1", "50", new Observer<ImageConsultationListResponse>() {
//            @Override
//            public void onSubscribe(Disposable d) {
//                System.out.println("getYJConsultationList");
//            }
//
//            @Override
//            public void onNext(ImageConsultationListResponse imageConsultationListResponse) {
//                list.clear();
//                list.addAll(imageConsultationListResponse.data.records);
//                adapter.notifyDataSetChanged();
//                System.out.println(list.size()+" aaaaaaaaaaa");
//                System.out.println(imageConsultationListResponse.data.total);
//            }
//
//            @Override
//            public void onError(Throwable e) {
//                e.printStackTrace();
//                refreshLayout.finishRefresh();
//                refreshLayout.finishLoadMore();
//            }
//
//            @Override
//            public void onComplete() {
//                refreshLayout.finishRefresh();
//                refreshLayout.finishLoadMore();
//            }
//        });
//    }
//
//    private void getKaYiUrl(String kayiPascId) {
//        RestProxy.getInstance().getKeYiUrl(kayiPascId, new Observer<KaYiUrlResponse>() {
//            @Override
//            public void onSubscribe(Disposable d) {
//
//            }
//
//            @Override
//            public void onNext(KaYiUrlResponse kaYiUrlResponse) {
//                Bundle bundle = new Bundle();
//                bundle.putString("url", kaYiUrlResponse.data.url);
//                startActivity(WebViewActivity.class, bundle);
//            }
//
//            @Override
//            public void onError(Throwable e) {
//
//            }
//
//            @Override
//            public void onComplete() {
//
//            }
//        });
//    }
//
//    private void agreeConsultation(String dispatchDiagId, String diagPascId, String dispatchType, String flag) {
//        RestProxy.getInstance().agreeConsultation(dispatchDiagId, diagPascId, dispatchType, flag, new Observer<BaseResponse>() {
//            @Override
//            public void onSubscribe(Disposable d) {
//
//            }
//
//            @Override
//            public void onNext(BaseResponse baseResponse) {
//                switch (type) {
//                    case 1:
//                        getYJConsultationList("0", "0");
//                        break;
//                    case 2:
//                        getYJConsultationList("0", "2");
//                        break;
//                    case 3:
//                        getYJConsultationList("1", "1");
//                        break;
//                    case 4:
//                        getYJConsultationList("1", "3");
//                        break;
//                }
//            }
//
//            @Override
//            public void onError(Throwable e) {
//
//            }
//
//            @Override
//            public void onComplete() {
//
//            }
//        });
//    }
//
//
//    private void getKaYiYJUrl(String dispatchType, String kayiPascId, String pascType, String kayiCheckPart, String docId, String docName) {
//        RestProxy.getInstance().getKaYiYJUrl(dispatchType, kayiPascId, pascType, kayiCheckPart, docId, docName, new Observer<KaYiUrlResponse>() {
//            @Override
//            public void onSubscribe(Disposable d) {
//
//            }
//
//            @Override
//            public void onNext(KaYiUrlResponse kaYiUrlResponse) {
//                Bundle bundle = new Bundle();
//                bundle.putString("url", kaYiUrlResponse.data.url);
//                startActivity(WebViewActivity.class, bundle);
//            }
//
//            @Override
//            public void onError(Throwable e) {
//
//            }
//
//            @Override
//            public void onComplete() {
//
//            }
//        });
//    }
//}
